package com.example.employee.controller;


import com.example.common.domain.Result;
import com.example.employee.domain.dto.UpdateEmployeeDTO;
import com.example.employee.domain.dto.UpdatePasswordDTO;
import com.example.employee.domain.vo.EmployeeInfoVO;
import com.example.employee.service.EmployeeService;
import com.example.upload.api.UploadClient;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@Tag(name = "员工接口相关")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/employee")
public class EmployeeController {

    private final EmployeeService employeeService;
    private final UploadClient uploadClient;

    /**
     * 修改员工信息
     *
     * @param updateEmployeeDTO
     */
    @PutMapping("/update")
    @Operation(summary = "修改员工信息")
    public Result<String> updateUserInfo(@RequestBody @Validated UpdateEmployeeDTO updateEmployeeDTO) {
        log.info("修改员工信息,员工信息为：{}", updateEmployeeDTO);
        employeeService.updateUserInfo(updateEmployeeDTO);
        return Result.success("员工信息更新成功");
    }

    // 修改密码
    @PutMapping("updatePwd")
    @Operation(summary = "员工修改密码")
    public Result updatePassword(@RequestBody @Validated UpdatePasswordDTO updatePasswordDTO) {
        log.info("员工修改密码:{}", updatePasswordDTO);
        employeeService.updatePassword(updatePasswordDTO);
        return Result.success("密码修改成功");
    }

    @PostMapping("/uploadFile")
    @Operation(summary = "员工上传头像")
    public Result<String> upload(@RequestParam("file") MultipartFile file) throws IOException {
        log.info("员工上传头像:{}", file);
        String imgUrl = uploadClient.uploadFile(file,"employee");
        return Result.success(imgUrl);
    }
    @GetMapping
    @Operation(summary = "获取员工信息")
    public Result<EmployeeInfoVO> getUserInfo() {
        log.info("获取用户信息");
        EmployeeInfoVO userInfoVO = employeeService.getEmployeeInfo();
        return Result.success(userInfoVO);
    }

}
